package top.liinyuxb.lycloud.samples.client2.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.liinyuxb.lycloud.samples.client2.config.UserConfig;
import top.liinyuxb.lycloud.samples.client2.entity.UserBaseInfoEntity;
import top.liinyuxb.lycloud.samples.client2.service.IUserBaseInfoService;
import top.linyuxb.lycloud.config.starter.annotation.LyConfigurationValue;
import top.linyuxb.lycloud.config.starter.common.LyConfigService;

import java.util.List;

/**
 * @author linyuxb
 * @date 2024/1/13 4:20 下午
 * @desc
 */

@RestController
@RequestMapping(value = "/test")
@Slf4j
public class ConfigController {
    @LyConfigurationValue(value = "${default.key01:5}")
    private Integer key01;
    @LyConfigurationValue(value = "${default.key02}")
    private String key02;
    @Value(value = "${default.key02}")
    private String valueKey02;
    @Value("${custom.property:}")
    private String myCustom;
    @Resource
    private UserConfig userConfig;

    @Resource
    private IUserBaseInfoService userBaseInfoService;

    @GetMapping("/getKey01")
    public Integer getKey01() {
        return key01;
    }

    @GetMapping("/getKey02")
    public String getKey02() {
        return key02;
    }

    @GetMapping("/getValueKey02")
    public String getValueKey02() {
        return valueKey02;
    }

    @GetMapping("/getKey03")
    public String getKey03() {
        return myCustom;
    }

    @GetMapping("/getUserConfig")
    public UserConfig getUserConfig() {
        return userConfig;
    }

    @GetMapping("/getUser")
    public List<UserBaseInfoEntity> getUser() {
        return userBaseInfoService.getUserInfos();
    }

    @GetMapping("/getServiceKey01")
    public Integer getServiceKey01() {
        return userBaseInfoService.getKey01();
    }

    @GetMapping("/getServiceKey02")
    public String getServiceKey02() {
        return userBaseInfoService.getKey02();
    }

    @GetMapping("/getServiceUserConfig")
    public UserConfig getServiceUserConfig() {
//        boolean a = true;
//        boolean b = false;
        return userBaseInfoService.getUserConfig();
    }

    @GetMapping("/checkServer")
    public String checkServer() {
        log.info("LyConfigService:{}", LyConfigService.getAllServer());
        return "ok";
    }

}
